<style lang="scss" scoped>
// .infobody {
//   height: 100%;
//   .content {
//     height: 100%;
//     padding-top: 0.44rem;
//     background-color: #f0f0f2;
//     .form-title {
//       padding: 0.12rem;
//       line-height: 0.26rem;
//       color: rgba(152, 165, 171, 1);
//       font-size: 0.18rem;
//     }
//     .info {
//       margin-left: 0.1rem;
//       margin-right: 0.1rem;
//       font-size: 0.16rem;
//       border: 0.01rem solid rgba(255, 255, 255, 0);
//       background-color: #ffffff;
//     }
//   }
// }
// .infobody{
//   .content{
//     height: 100%;
//   }
// }
</style>

<template>
    <div class="infobody">
        <dealer-topbar :title="title" @changeStatus="changeStatus" @delItem="delItem" @saveItem="saveItem"></dealer-topbar>
        <div class="content">
            <p class="form-title">经销商信息</p>
            <div class="info">
                <Form :model="agentInfo" >
                    <FormItem  label="名称" >
                        <Input :disabled="status"  v-model="agentInfo.agentName" placeholder="请输入名称" />
                    </FormItem>
                    <FormItem  label="联系方式" >
                        <Input :disabled="status"  v-model="agentInfo.phone" placeholder="请输入联系方式" />
                    </FormItem>
                     <FormItem  label="地址" >
                        <Input :disabled="status"  v-model="agentInfo.addr" placeholder="请输入地址" />
                    </FormItem>
                </Form>
            </div>
        </div>
    </div>
</template>

<script>
import dealerTopbar from "@/views/component/dealerTopbar.vue";
import {sampleData} from 'api/index.js';
export default {
  data() {
    return {
      title: "经销商",
      status: true,
      agentInfo: {
        id:"",
        agentName: "",
        phone: "",
        addr:"",
        userId:""
      }
    };
  },
  methods: {
    changeStatus(param) {
      this.status = param.btnEdit;
    },
    saveItem(){
      if (this.$store.state.agentOperation == "edit") {
        //调更新接口
        let obj=this.agentInfo;
        sampleData.agentUpdate(obj).then(res=>{
          if(res.code==0||res.code==200){
            this.$Message.success("修改成功")
            this.$router.push('/agentList')
          }else{
            this.$Message.error(res.msg)
          }
        }).catch(error=>{
          this.$Message.error(error)
        })
      } else {
        //调新增接口
        let obj=this.agentInfo;
        sampleData.agentAdd(obj).then(res=>{
          if(res.code==0||res.code==200){
            this.$Message.success("添加成功")
            this.$router.push('/agentList')
          }else{
            this.$Message.error(res.msg)
          }
        }).catch(error=>{
          this.$Message.error(error)
        })
      }      
    },
    delItem(){
      let obj={
        agentId:this.$route.query.agentId
      }
      sampleData.agentDelete(obj).then(res=>{
        if(res.code==0||res.code==200){
          this.$Message.success("删除成功");
          this.$router.push('/agentList')
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(error=>{
        this.$Message.error(error);
      })      
    },
    getAgentById(){
      let obj={
        id:this.$route.query.agentId
      }
      sampleData.getAgentById(obj).then(res=>{
        if(res.code==0||res.code==200){
          this.agentInfo=res.agentEntity;
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(error=>{
        this.$Message.error(error);
      })
    }
  },
  mounted() {
    if (this.$store.state.agentOperation == "edit") {
      this.status = true;
      this.getAgentById();
    } else {
      this.status = false;
    }
  },
  components: {
    dealerTopbar
  }
};
</script>

